package com.codingfuture.erp_system.web.controller;

import com.codingfuture.erp_system.dto.PageData;
import com.codingfuture.erp_system.entity.Month;
import com.codingfuture.erp_system.service.MonthService;
import com.codingfuture.erp_system.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/v2")
@RestController
public class MonthController {

    @Autowired
    private MonthService monthService;

    @GetMapping("/statistics/month")
    public Result findByMonth(@RequestParam(defaultValue = "1") int page,
                              @RequestParam(defaultValue = "10") int rows,
                              @RequestParam(defaultValue = "2023") Integer year) {
        Page<Object> startPage = PageHelper.startPage(page, rows);
        List<Month> list = monthService.findByMonth(year);
        PageData<Month> data = new PageData<>(list, startPage.getTotal());
        return Result.ok(data);
    }

}
